import useUser from "@/stores/user";

export default {
    mounted(el, binding, vnode) {
        const userStore = useUser();
        const {value} = binding;
        const all_permission: string = "*:*:*";
        const permissions = userStore.permissions;

        if (value && value instanceof Array && value.length > 0) {
            const permissionFlag: string[] = value

            //判断权限是否满足
            const hasPermission: boolean = permissions.some((permission: string) => {
                return all_permission === permission || permissionFlag.includes(permission)
            })

            if (!hasPermission) {
                el.parentNode && el.parentNode.removeChild(el)
            }
        }else {
            throw new Error(`请设置操作权限标签值`);
        }

    }
}